package com.sdry.service.impl.hpf;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.hpf.LabelMapper;
import com.sdry.model.hpf.Bom;
import com.sdry.model.hpf.Label;
import com.sdry.service.hpf.LabelService;

/** 
* 标签service实现类
* @author lian 
* @version 1.0
* @time 2018年10月15日 下午5:23:17
*/

@Service
public class LabelServiceImp implements LabelService {

	@Resource
	private LabelMapper labelMapper;
	
	/**
	 * 查询标签总行数
	 * @param label 标签
	 * @return
	 */
	@Override
	public int countLabel(Label label) {
		return labelMapper.countLabel(label);
	}

	/**
	 * 分页查询标签
	 * @param map 查询条件的集合
	 * @return
	 */
	@Override
	public List<Label> listPageLabel(Map<String, Object> map) {
		return labelMapper.listPageLabel(map);
	}

	/**
	 * 添加标签
	 * @param label 标签
	 * @return
	 */
	@Override
	public int insertLabel(Label label) {
		return labelMapper.insertLabel(label);
	}

	/**
	 * 修改标签
	 * @param label 标签
	 * @return
	 */
	@Override
	public int updateLabel(Label label) {
		return labelMapper.updateLabel(label);
	}

	/**
	 * 删除标签
	 * @param str id组成的字符串
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public int deleteLabel(String str) {
		int isSuccess = 0;
		String[] split = str.split(",");
		try {
			for (String rid : split) {
				isSuccess = labelMapper.deleteLabel(Long.parseLong(rid));
			}
		}catch (
		Exception e) {
			e.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		return isSuccess;
	}

}
